package com.hjm.project.salaryPlan.agentActivityDetails.controller;

import java.util.List;

import com.hjm.project.salaryPlan.agentActivity.service.IAgentActivityService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.hjm.framework.aspectj.lang.annotation.Log;
import com.hjm.framework.aspectj.lang.enums.BusinessType;
import com.hjm.project.salaryPlan.agentActivityDetails.domain.AgentActivityDetails;
import com.hjm.project.salaryPlan.agentActivityDetails.service.IAgentActivityDetailsService;
import com.hjm.framework.web.controller.BaseController;
import com.hjm.framework.web.domain.AjaxResult;
import com.hjm.common.utils.poi.ExcelUtil;
import javax.annotation.Resource;
import com.hjm.framework.web.page.TableDataInfo;

/**
 * 活动参与人员明细Controller
 * 
 * @author maker-platform
 * @date 2022-04-07
 */
@Controller
@RequestMapping("/salaryPlan/agentActivityDetails")
public class AgentActivityDetailsController extends BaseController {
    private String prefix = "salaryPlan/agentActivityDetails";

    @Resource
    private IAgentActivityDetailsService agentActivityDetailsService;

    @Resource
    private IAgentActivityService agentActivityService;

    @RequiresPermissions("salaryPlan:agentActivityDetails:view")
    @GetMapping()
    public String agentActivityDetails() {
        return prefix + "/agentActivityDetails";
    }

    /**
     * 查询活动参与人员明细列表
     */
    @RequiresPermissions("salaryPlan:agentActivityDetails:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(AgentActivityDetails agentActivityDetails) {
        startPage();
        List<AgentActivityDetails> list = agentActivityDetailsService.selectAgentActivityDetailsList(agentActivityDetails);
        return getDataTable(list);
    }

    /**
     * 导出活动参与人员明细列表
     */
    @RequiresPermissions("salaryPlan:agentActivityDetails:export")
    @Log(title = "活动参与人员明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(AgentActivityDetails agentActivityDetails) {
        List<AgentActivityDetails> list = agentActivityDetailsService.selectAgentActivityDetailsList(agentActivityDetails);
        ExcelUtil<AgentActivityDetails> util = new ExcelUtil<AgentActivityDetails>(AgentActivityDetails.class);
        return util.exportExcel(list, "agentActivityDetails");
    }

    /**
     * 新增活动参与人员明细
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增活动人员
     */
    @GetMapping("/addDetails")
    public String addDetails() {
        return prefix + "/addDetails";
    }

    /**
     * 新增保存活动参与人员明细
     */
    @RequiresPermissions("salaryPlan:agentActivityDetails:add")
    @Log(title = "活动参与人员明细", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(AgentActivityDetails agentActivityDetails) {
        return toAjax(agentActivityDetailsService.insertAgentActivityDetails(agentActivityDetails));
    }

    /**
     * 修改活动参与人员明细
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap) {
        AgentActivityDetails agentActivityDetails = agentActivityDetailsService.selectAgentActivityDetailsById(id);
        String[] scope = agentActivityDetails.getLevelScope().split(",");
        agentActivityDetails.setStartGrade(scope[0].substring(1,2));
        agentActivityDetails.setEndGrade(scope[scope.length-1].substring(1,2));
        mmap.put("agentActivityDetails", agentActivityDetails);
        return prefix + "/edit";
    }

    /**
     * 修改保存活动参与人员明细
     */
    @RequiresPermissions("salaryPlan:agentActivityDetails:edit")
    @Log(title = "活动参与人员明细", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(AgentActivityDetails agentActivityDetails) {
        return toAjax(agentActivityDetailsService.updateAgentActivityDetails(agentActivityDetails));
    }

    /**
     * 删除活动参与人员明细
     */
    @RequiresPermissions("salaryPlan:agentActivityDetails:remove")
    @Log(title = "活动参与人员明细", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(agentActivityDetailsService.deleteAgentActivityDetailsByIds(ids));
    }

    /**
     * 修改第三方系统访问请求
     */
    @GetMapping("/detail/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap) {
        //活动详情
        AgentActivityDetails agentActivityDetails = agentActivityDetailsService.selectAgentActivityDetailsById(String.valueOf(id));
        mmap.put("detail", agentActivityDetails);
        return prefix + "/details";
    }


    /**
     * 活动送审
     */
    @Log(title = "活动送审", businessType = BusinessType.DELETE)
    @PostMapping( "/sendAudit")
    @ResponseBody
    public AjaxResult sendAudit(String id) {
        return toAjax(agentActivityDetailsService.sendAudit(id));
    }

    /**
     * 审核页面
     */
    @GetMapping("/auditInfo/{id}")
    public String auditInfo(@PathVariable("id") Integer id, ModelMap mmap) {
        AgentActivityDetails details = agentActivityDetailsService.selectAgentActivityDetailsById(String.valueOf(id));
        mmap.put("details", details);
        return prefix + "/auditInfo";
    }


    /**
     * 活动送审
     */
    @Log(title = "活动审核", businessType = BusinessType.DELETE)
    @PostMapping( "/saveAuditInfo")
    @ResponseBody
    public AjaxResult saveAuditInfo(AgentActivityDetails agentActivityDetails) {
        return toAjax(agentActivityDetailsService.saveAuditInfo(agentActivityDetails));
    }
}
